package com.cjm.one.webmanager.service.system.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cjm.one.model.base.BaseDeleteMoreVo;
import com.cjm.one.model.base.PasswordDto;
import com.cjm.one.model.system.dto.SysUserInfoDto;
import com.cjm.one.model.system.dto.SysUserInfoFromDto;
import com.cjm.one.model.system.entity.SysUserInfo;
import com.cjm.one.model.system.entity.SysUserRole;
import com.cjm.one.model.system.vo.SysUserInfoVo;
import com.cjm.one.system.client.SyStemUserClient;
import com.cjm.one.webmanager.service.system.SysUserInfoService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class SysUserInfoServiceImpl implements SysUserInfoService {
    @Resource
    private SyStemUserClient syStemUserClient;
    @Override
    public SysUserInfoVo getSysUserById(Long id) {
        SysUserInfoVo sysUserInfoVo = syStemUserClient.getUserInfoById(id).getData();
        log.info("获取用户信息成功:{}", sysUserInfoVo);
        return sysUserInfoVo;
    }

    @Override
    public Boolean addSysUser(SysUserInfo sysUserInfo) {
        return syStemUserClient.saveUser(sysUserInfo).getData();
    }



    @Override
    public Boolean deleteSysUser(Long id) {
        return  syStemUserClient.deleteSysUser(id).getData();
    }

    @Override
    public Boolean updateSysUser(SysUserInfoDto sysUserInfoDto) {
        log.info("修改用户信息:{}", syStemUserClient.updateSysUser(sysUserInfoDto));
        return syStemUserClient.updateSysUser(sysUserInfoDto).getData();
    }

    @Override
    public Boolean updateSysUserPassword(PasswordDto passwordDto) {
        return syStemUserClient.updateSysUserPassword(passwordDto).getData();
    }

    @Override
    public Boolean updateSysUserStatus(SysUserInfoDto sysUserInfoDto) {
        return syStemUserClient.updateSysUserStatus(sysUserInfoDto).getData();
    }

    @Override
    public List<SysUserRole> getSysUserRole(Long userId) {
        return syStemUserClient.getSysUserRoleByIdList(userId).getData();
    }

    @Override
    public Page<SysUserInfoVo> getSysUserPage(SysUserInfoFromDto queryVo) {
        return syStemUserClient.getSysUserPage(queryVo).getData();
    }

    @Override
    public BaseDeleteMoreVo deleteSysUserMore(List<Long> ids) {
        Integer data = syStemUserClient.deleteSysUserMore(ids).getData();
        BaseDeleteMoreVo baseDeleteMoreVo = new BaseDeleteMoreVo();
        baseDeleteMoreVo.setTotal(ids.size());
        if (data == 0) {
            baseDeleteMoreVo.setFlag(false);
            baseDeleteMoreVo.setCount(0);
            return baseDeleteMoreVo;
        }
        baseDeleteMoreVo.setFlag(true);
        baseDeleteMoreVo.setCount(data);

        return baseDeleteMoreVo;
    }

    @Override
    public Boolean resetPassword(PasswordDto passwordDto) {
        return syStemUserClient.resetPassword(passwordDto).getData();
    }

    @Override
    public SysUserInfo getLoginUser(String token) {
        return syStemUserClient.userInfo(token).getData();
    }


}
